package com.nineclock.system.easyescel;


import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.nineclock.system.service.SysCompanyUserService;

import java.util.ArrayList;
import java.util.List;


public class MemberParseListener extends AnalysisEventListener<ExcelMember> {

    private List<ExcelMember> excelMembers = new ArrayList<>();
    private SysCompanyUserService companyUserService;

    public MemberParseListener(SysCompanyUserService sysCompanyUserService) {
        this.companyUserService = sysCompanyUserService;
    }


    //该方法每解析一行数据, 就会触发一次
    @Override
    public void invoke(ExcelMember data, AnalysisContext context) {
        excelMembers.add(data);
    }

    //该方法是等所有行解析完毕之后触发
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        companyUserService.importData(excelMembers);

    }
}
